package com.diwu.diwuoj.diwuojserver.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description rabbitmq 的交换机与队列的配置
 * @Author diwu
 * @Date 2024/8/8
 */
@Configuration
public class RabbitmqConfig {

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public DirectExchange codeExchange(){
        System.out.println("创建交换机成功");
        return ExchangeBuilder.directExchange("code_exchange").build();
    }

    /**
     * 创建对列
     * @return
     */
    @Bean
    public Queue codeQueue(){
        System.out.println("创建队列成功");
        return  new Queue("code_queue");
    }

    /**
     * 绑定交换机与队列
     * @param codeQueue
     * @param codeExchange
     * @return
     */
    @Bean
    public Binding bindingQueue(Queue codeQueue, DirectExchange codeExchange){
        System.out.println("绑定交换机与队列成功");
        return BindingBuilder.bind(codeQueue).to(codeExchange).with("codeKey");
    }
}
